<?php
defined('IN_TS') or die('Access Denied.');

$userid = aac('user')->isLogin();

//判断发布者状态
if(aac('user')->isPublisher()==false) tsNotice('不好意思，你还没有权限发布内容！');

switch($ts){

	case "":
		$arrOptions = $new['plan']->findAll('plan_options');
		foreach($arrOptions as $item){
			$strOption[$item['optionname']] = stripslashes($item['optionvalue']);
		}
		$arrGroup = $new['plan']->findAll('group','isplace=2','groupid asc');
		if ($strOption['allowpost'] == 0 && $TS_USER['isadmin'] == 0) {
//        if ($TS_APP['allowpost'] == 0 && $TS_USER['isadmin'] == 0) {
            tsNotice('系统设置不允许会员发方案！');
        }

		$title = '发布方案';
		include template("add");
	
		break;
	
	case "do":
	
		$title = trim($_POST['title']);
		$typeid = intval($_POST['typeid']);
		$content = tsClean($_POST['content']);

		$img_path = getTextPhotos(tsDecode($content));

		if($img_path==array()){
			tsNotice('请至少插入一张图片作为封面！');
		};
		$count = count($img_path);
		$img_path = $img_path[$count-1];
		//$url=preg_replace('#/$#','',SITE_URL);
		//$img_path = $url.$img_path;

		if($title == '' || $content == ''){
			tsNotice('标题和内容不能为空');
		}

        //1审核后显示0不审核
        if ($TS_APP['isaudit'] == 1) {
            $isaudit = 1;
        } else {
            $isaudit = 0;
        }


		
		$planid = $new['plan']->create('plan',array(
			
			'userid'	=> $userid,
			'title'	=> $title,
			'typeid' => $typeid,
			'content' => $content,
			'isaudit'=>$isaudit,
			'addtime'	=> time(),
		));


		
		//上传
		$arrUpload = tsUploadPhotoUrl($img_path,$planid,'plan',array('jpg','gif','png'));
		
		if($arrUpload){

			$new['plan']->update('plan',array(
				'planid'=>$planid,
			),array(
				'path'=>$arrUpload['path'],
				'photo'=>$arrUpload['url'],
			));

		}

		header("Location: ".tsUrl('plan','show',array('id'=>$planid)));
	
		break;
		
	//地图 
	case "map":
	
		$dd = isset($_GET['dd']) ? $_GET['dd'] : '中国北京';

		include template('add_map');
	
		break;

}